
import store from "@/store";
export default
    [
        {
            path: "/center",
            component: () => import("@/pages/Center"),
            meta: { isShow: true },
            children: [
                {
                    path: "myorder",
                    component: () => import("@/pages/Center/MyOrder"),
                },
                {
                    path: "grouporder",
                    component: () => import("@/pages/Center/GroupOrder"),
                },
                {
                    //重定向
                    path: "/center",
                    redirect: "/center/myorder",
                },
            ]
        }
        ,
        {
            path: "/paysuccess",
            component: () => import("@/pages/PaySuccess"),
            meta: { isShow: true },
            beforeEnter: (to, from, next) => {
                if (from.path == "/pay") {
                    next();
                } else {
                    next(false);
                }
            }
        }
        ,
        {
            path: "/pay",
            component: () => import("@/pages/Pay"),
            meta: { isShow: true },
            beforeEnter: (to, from, next) => {
                if (from.path == "/trade") {
                    next();
                } else {
                    next(false);
                }
            }
        }
        ,
        {
            path: "/trade",
            component: () => import("@/pages/Trade"),
            meta: { isShow: true },
            beforeEnter: (to, from, next) => {
                if (from.path == "/shopcart") {
                    next();
                } else {
                    next(false);
                }
            }
        }
        ,
        {
            path: "/shopcart",
            component: () => import("@/pages/ShopCart"),
            meta: { isShow: true }
        }
        ,
        {
            name: "addcartsuccess",
            path: "/addcartsuccess",
            component: () => import("@/pages/AddCartSuccess"),
            meta: { isShow: true },
            //对进入addcartsuccess组件设置单独的独享路由守卫
            beforeEnter: (to, from, next) => {
                let token = store.state.user.token;
                //登录时
                if (token) {
                    //登录，按顺序从detail来
                    if (from.path.indexOf("/detail") != -1 || from.path.indexOf("/login") != -1) {
                        next();
                    } else {
                        //登录，从其他组件直接跳转
                        next(false);
                    }
                } else {
                    //未登录，按顺序从detail来
                    if (from.path.indexOf("/detail") != -1) {
                        let redirect = "/addcartsuccess"
                        next(`/login?redirect=${redirect}`);
                    } else {
                        //未登录，从其他组件直接跳转
                        next(false)
                    }
                }
            }
        }
        ,
        {
            path: "/detail/:skuId?",
            component: () => import("@/pages/Detail"),
            meta: { isShow: true },
        },
        {
            path: "/home",
            component: () => import("@/pages/Home"),
            meta: { isShow: true },
        },
        {
            name: "search",
            path: "/search/:keyword?",
            component: () => import("@/pages/Search"),
            meta: { isShow: true },
        },
        {
            path: "/login",
            component: () => import("@/pages/Login"),
            meta: { isShow: false },
        },
        {
            path: "/register",
            component: () => import("@/pages/Register"),
            meta: { isShow: false },
        },

        //重定向，访问根目录，定位到首页
        {
            path: "/",
            redirect: "/home",
        },
    ]   
